<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<base href="<%=basePath%>">
<meta charset="UTF-8">
<title>商城管理系统</title>
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/css/bootstrap.min.css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/css/main.css">
<link rel="stylesheet"
	href="//apps.bdimg.com/libs/jqueryui/1.10.4/css/jquery-ui.min.css">
<script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/js/main.js"></script>
<script src="http://www.jq22.com/jquery/jquery-migrate-1.2.1.min.js"></script>
<script src="${pageContext.request.contextPath}/js/jqprint.js"></script>
<script src="${pageContext.request.contextPath}/js/jqueryui.js"></script>
<script src="//apps.bdimg.com/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<style>
.box_content {
	height: 100px;
}

.listTr button {
	border-radius: 6px;
	background-color: #337ab7;
	color: #ffffff；outline:none
}

.pageChange {
	float: right;
	color: #337ab7;
}

.pageChange>span {
	cursor: pointer
}

.pageChange>span:hover {
	color: blue
}
.bgBox2{
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    background-color: rgba(0, 0, 0, 0.26);
    /*background-color: black;*/
    /*opacity: 0.3;*/
    z-index: 100;
    visibility: hidden;
    /*border: 1px solid red;*/
}
#box2{
    width: 540px;
    height: 428px;
    border-radius: 10px;  
    position: relative;
    margin: 150px auto;
}
</style>
<script>
	$(function() {
		$("#startTime").datepicker();
		$("#endTime").datepicker();
		$("#startTime").datepicker("option", "dateFormat", "yy-mm-dd");
		$("#endTime").datepicker("option", "dateFormat", "yy-mm-dd");
	})
</script>
</head>
<body>


	<%@ include file="header.jsp"%>
	<%@ include file="left.jsp"%>
	<div id="index"
		style="position: absolute;left: 180px;top: 80px;bottom: 0;right: 0;">
		<section id="main">
			<div class="scrollbar1-1" id="style1-1">
				<div class="main_div">
					<div class="main_title">
						<span>发货管理</span>
					</div>
					<form id="deliveryform" class="form-inline"
						style="margin-top: 30px;margin-left: 20px">
						<div class="form-group">
							<label for="orderCode"> 订单编号:</label> <input type="text"
								class="form-control" name="orderFormId" id="orderFormId"
								placeholder="">
						</div>
						<input style="display:none" value="8" name="pageCount"
							id="pageCount" />
						<div class="form-group">
							<label for="ProductName">消费者:</label> <input type="text"
								class="form-control" name="userName" id="userName">
						</div>
						<div class="form-group">
							<label for="phone"> 消费者电话:</label> <input type="text" id="phone"
								class="form-control" placeholder="">
						</div>
						<div class="form-group">
							<label for="ProductName"> 开始时间:</label> <input type="text"
								class="form-control" name="" id="startTime" placeholder="">
						</div>
						<div class="form-group">
							<label for="userName"> -结束时间:</label> <input type="text"
								class="form-control" name="" id="endTime" placeholder="">
						</div>
						<button type="button" onclick="selectinfo()"
							class="btn btn-primary">查询</button>
					</form>
				</div>
				<div class="force-overflow1-1">
					<table id="showtable"
						class="table table-condensed table-bordered table-hover"
						style="text-align: center">
						<tr style="background-color:#f8f8f8">
							<th style="text-align: center;color: #000">序号</th>
							<th style="text-align: center;color: #000">订单编号</th>
							<th style="text-align: center;color: #000">顾客</th>
							<th style="text-align: center;color: #000">送货地址</th>
							<th style="text-align: center;color: #000">联系电话</th>
							<th style="text-align: center;color: #000">订单时间</th>
							<th style="text-align: center;color: #000">订单总金额</th>
							<th style="text-align: center;color: #000">订单详情</th>
							<th style="text-align: center;color: #000">操作</th>
						</tr>
					</table>
					<div class="bgBox2" style="visibility:hidden">
						<div id="box2">
							<div class="box_header textYellow">
								<span>详细资料</span>
							</div>
							<div class="scrollbar1-2" id="style1-1">
								<div class="box_content">
									<form id="detailFrom" class="form-horizontal"
										style="margin-top: 30px;margin-left: 20px">
										<div class="form-group">
										    <span id="orderformid" style="display:none"></span>
											<label class="col-xs-4 control-label">快递公司：</label>
											<div class="col-xs-5">
												<select id="Logistics" class="form-control">
													<option value="-1">请选择</option>
													<option value="SF">顺丰</option>
													<option value="EMS">EMS</option>
													<option value="ZJS">宅急送</option>
													<option value="YTO">圆通</option>
													<option value="HTKY">百世快递</option>
													<option value="ZTO">中通</option>
													<option value="YD">韵达</option>
													<option value="STO">申通</option>
													<option value="DBL">德邦</option>
													<option value="UC">优速</option>
													<option value="JD">京东</option>
													<option value="XFEX">信丰</option>
													<option value="QFKD">全峰</option>
													<option value="KYSY">跨越速运</option>
													<option value="ANE">安能小包</option>
													<option value="FAST">快捷快递</option>
													<option value="GTO">国通</option>
													<option value="HHTT">天天快递</option>
												</select>
											</div>
										</div>
										<div class="form-group">
											<label class="col-xs-4 control-label">物流单号：</label>
											<div class="col-xs-5">
												<input type="text" class="form-control" id="logisticsNum"
													 placeholder="请输入物流单号">
											</div>
										</div>
										<div class="col-xs-4 col-xs-offset-2">
											<button id="setButton" class="col-xs-12 btn btn-primary"
												type="button" onclick="sendOrderNum()">提交</button>
										</div>
									</form>
								</div>
								<div class="force-overflow1-2"></div>
							</div>
							<div class="box_footer">
								 <ul>
									<li id="sureDetail" onclick="motaiHidden2()">取消</li>
									<!-- <li id="prints" onclick="prints()">打印</li> -->
								</ul> 
							</div>
						</div>
					</div>
					<div class="bgBox" style="visibility:hidden">
						<div id="box">
							<div class="box_header textYellow">
								<span>详细资料</span>
							</div>
							<div class="scrollbar1-2" id="style1-1">
								<div class="box_content">
									<table class="table table-condensed table-bordered table-hover"
										style="text-align: center" id="showtable2">
										<tr>
											<th style="text-align: center">产品名称</th>
											<th style="text-align: center">产品单价</th>
											<th style="text-align: center">产品数量</th>
											<th style="text-align: center">产品总价</th>
										</tr>
									</table>
								</div>
								<div class="force-overflow1-2"></div>
							</div>
							<div class="box_footer">
								<ul>
									<li id="sureDetail" onclick="motaiHidden()">确认</li>
								<!-- <li id="prints" onclick="prints()">打印</li> -->	
								</ul>
							</div>
						</div>
					</div>
					<div class="pageChange">
						<span onclick="prePage()">&nbsp;&nbsp;上一页&nbsp;&nbsp;</span> <span
							onclick="nextPage()">&nbsp;&nbsp;下一页&nbsp;&nbsp;</span> <em>
							&nbsp; 第&nbsp;<span id="pageNum">1</span>&nbsp;页&nbsp;&nbsp;
						</em> <em>/&nbsp;&nbsp;共&nbsp;<span id="totalpage"></span>&nbsp;页
						</em> <em>&nbsp;&nbsp;&nbsp;跳到第<input id="searchInput"
							style="width:46px" maxlength="4" type="text">页
						</em>
						<button class="btn btn-primary" onclick="searchPage()">搜索</button>
					</div>
				</div>
			</div>
		</section>
	</div>
	<script type="text/javascript">
		function showMotais() { //弹出详情页面
			$(".bgBox").css("visibility", "visible")
		}
		function motaiHidden() { //隐藏详情页面
			$(".bgBox").css("visibility", "hidden")
		}
	function motaiHidden2() { //隐藏详情页面
			$(".bgBox2").css("visibility", "hidden")
		}
		$(function() {
			selectinfo()
		})
	
		
	
		function selectinfo() {
			var orderFormId = $("#orderFormId").val();
			var userName = $("#userName").val();
			var phone = $("#phone").val();
			var pageNum = $("#pageNum").html();
			var pageCount = $("#pageCount").val();
			var startTime = $("#startTime").val();
			var endTime = $("#endTime").val();
			if (phone == "") {
				phone = null
			}
			if (orderFormId == "") {
				orderFormId = null
			}
			if (userName == "") {
				userName = null
			}
	
			if (startTime == "") {
				startTime = null
			} else {
				startTime = startTime + " 00:00:00"
			}
			if (endTime == "") {
				endTime = null
			} else {
				endTime = endTime + " 23:59:59"
			}
			$.post(urls + "directAction/getOrderFormBySuperInfo",
				{
					userName : userName,
					pageNum : pageNum,
					pageCount : pageCount,
					phone : phone,
					status : 1,
					typeId : 3,
					startTime : startTime,
					endTime : endTime
				},
				function(data) {
					//console.log(data)
					if (data) {
						var totalpage = data.totalpage;
						var orderlist = data.orderlist;
						var table = $("#showtable");
						$("tr").remove(".addtr");
						for (var i = 0; i < orderlist.length; i++) {
							var append = "<tr class='addtr'><td>" + (i + 1) + "</td>" +
								"<td >" + orderlist[i].orderFormId + "</td>" +
								"<td>" + orderlist[i].userName + "</td>" +
								"<td>" + orderlist[i].address + "</td>" +
								"<td>" + orderlist[i].phone + "</td>" +
								"<td>" + orderlist[i].orderFormTime + "</td>" +
								"<td>" + orderlist[i].totalMoney + "</td>" +
							/*	"<td><button class='btn btn-info' onclick='detailinfo(\"" +
								orderlist[i].OrderFormDetails[0].productName + "|$" +
								orderlist[i].OrderFormDetails[0].unitPrice + "|$" +
								orderlist[i].OrderFormDetails[0].quantity + "|$" +
								orderlist[i].OrderFormDetails[0].totalPrices + "|$" +
								"\")'>查看详情</button></td>" +*/
								"<td><button class='btn btn-info' onclick='detailinfo(\"" +
								orderlist[i].orderFormId +
								"\")'>查看详情</button></td>" +
								"<td><button class='btn btn-primary' onclick='sendProduct(\"" + orderlist[i].orderFormId + "\","+orderlist[i].superId+")'>发货</button></td></tr>";
							table.append(append);
						}
						$("#totalpage").html(totalpage);
					}
				}
				, "json"
			)
		}
		function detailinfo(e) {
			showMotais()
           $.post(urls + "orderFormAction/getOrderFormDetailsByOrderFormID", {
				orderFormId : e,
			}, function(res) {
				var tables = $("#showtable2");
			$(".addtr2").empty();
		
		
			    for(var z in res){
			    	var append = "<tr class='addtr2'><td >" +res[z].productName+  "</td>" +
				"<td>" + res[z].unitPrice + "</td>" +
				"<td>" + res[z].quantity + "</td>" +
				"<td>" + res[z].totalPrices + "</td></tr>";
        	tables.append(append);
        }
			})
		//	var arr = e.split("|$");

			//$("#sendAdd").text(arr[7])
			//$("#userPhones").text(arr[6])
			//$("#users").text(arr[5])
			//$("#orderTimes").text(arr[3])
			//$("#payways").text(arr[2])
			//$("#allMoney").text(arr[1])
			//$("#shippingFees").text(arr[4])
			//$("#superName").text(arr[8])
			//$("#orderFormids").text(arr[0])
		
		}
		function motaiHidden() {
			$(".bgBox").css("visibility", "hidden");
		}
		function sendProduct(orderId,superid) { //点击发货时将商品订单id与用户id发送到后台
			$(".bgBox2").css("visibility", "visible");
			$("#logisticsNum").val("");
			$("#orderformid").text(orderId)
			
		/* 	$.post(urls + "orderFormAction/TheSupermarketDelivery", {
				orderFormID : orderId,
			}, function(res) {
				if (res == true) {
					alert("发货成功")
					selectinfo()
				} else {
					alert("发货失败")
				}
			}) */
		}
		
		function sendOrderNum(){
		if($("#Logistics").val()==-1){
		 alert("请选择快递公司");
		 return;
		}
		if($("#logisticsNum").val().length<8){
		 alert("请输入正确的物流单号");
		 return;
		}
		 	$.post(urls + "directAction/TheSupermarketDelivery", {
				orderFormID : $("#orderformid").text(),
				trackingNum:$("#Logistics").val()+"|$|"+$("#logisticsNum").val()
			}, function(res) {
				if (res == true) {
					alert("发货成功")
					motaiHidden2()
					selectinfo()
				} else if(res=false){
					alert("发货失败")
				}
			})
		}
		
	</script>
	
	
</body>
</html>